/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* getKthFromEnd(ListNode* head, int k) {
        if(head==NULL)
            return head;
        
        ListNode*i=head;
        ListNode*j=head;
 
         while(k--&&j!=NULL)
        {
                j=j->next;
        }
        while(j)
        {
           
            j=j->next;
            i=i->next;
 
        }
        return i;
    }
};